.fp 5 CW
.de Af
.ds ;G \\*(;G\\f\\$1\\$3\\f\\$2
.if !\\$4 .Af \\$2 \\$1 "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
..
.de aF
.ie \\$3 .ft \\$1
.el \{\
.ds ;G \&
.nr ;G \\n(.f
.Af "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
\\*(;G
.ft \\n(;G \}
..
.de L
.aF 5 \\n(.f "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de LR
.aF 5 1 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de RL
.aF 1 5 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de EX		\" start example
.ta 1i 2i 3i 4i 5i 6i
.PP
.RS 
.PD 0
.ft 5
.nf
..
.de EE		\" end example
.fi
.ft
.PD
.RE
.PP
..
.TH STROPT 3
.SH NAME
stropt \- table driven option expression evaluator
.SH SYNOPSIS
.L "#include <namval.h>"
.br
.L "int stropt(char* s, struct namval* tab,
.br
.L "           int (*fun)(void* a, struct namval* p, int n, char* v),"
.br
.L "           void* a)"
.SH DESCRIPTION
.I stropt
parses option expressions in the nul-terminated string
.I s
using the option names in
.IR tab .
.I tab
is an array of
.B "struct namval"
name value pairs:
.EX
char*	name;
int	value;
.EE
The last entry must be followed by a sentinel with
.B name
set to 0.
.PP
An option expression contains 0 or more of [\fBno\fP]\fIname\fP[=\fIvalue\fP]
separate by
.B space
or
.BR tab ,
where
.I name
must be one of the option names in
.IR tab ,
.I value 
is an optional value, and
.B no
is for Boolean options.
Each option is passed to
.I fun
for processing.
.I a
is the
.L void*
pointer that is passed from the
.I stropt
call but is otherwise not interpreted.
.I p
points to the option name value pair from
.IR tab .
.I n
is 0 if
.B no
preceded the option
.I name
and
.I v
points to the beginning of the option
.I value
in
.IR s .
and
If
.I name
is not found in
.I tab
then
.I fun
is called with 
.I p
pointing to an internal
.I namval
entry with
.I p\->name
pointing to the unknown option and
.I p\->value
set to the
.I value
of the sentinel entry in
.IR tab .
.PP
If
.I fun
returns non-zero then this value is returned and no further
options are processed.
Otherwise
.I stropt
returns 0 after processing all options.
